using System;
using System.Collections.Generic;
using System.Text;
using Castle.MonoRail.TestSupport;
using IronMis2.Controllers;
using IronMis2.Models;
using NUnit.Framework;

namespace IronMis2.Tests.Controllers
{
    [TestFixture]
    public class UserControllerTestCase:ARBaseControllerTest
    {
        UserController controller;
        [SetUp]
        public void Init()
        {
            controller = new UserController();
            PrepareController(controller);
        }

        [Test]
        public void CreateNewUser()
        {
            Employee emp=new Employee();
            emp.Name = "test";
            emp.Password = "test";
            emp.UserId = "test1";
            controller.Create(emp);

            Employee dbemp = (Employee) controller.PropertyBag["employee"];
            Assert.AreEqual("test1",dbemp.UserId);
            emp.DeleteAndFlush();

            Assert.AreEqual("/User/Detail.rails",Response.RedirectedTo);
        }

        [Test]
        public void ShowUserDetai()
        {
            Employee emp = new Employee();
            controller.Detail(emp);
            Assert.AreEqual(@"User\Detail",controller.SelectedViewName);
        }

       [Test]
        public void UpdateUser()
       {
           Employee emp = Employee.FindFirst();
            string oldUserId = emp.UserId;
           Guid oldId = emp.Id;
//           emp.Name = "test";
          
//           controller.Update(oldId,emp.UserId,"test","1234567890");
           controller.Update(emp);
           Assert.IsNotNull(controller.PropertyBag["employee"]);
           Employee dbemp = Employee.Find(oldId);
           Assert.AreEqual(emp.UserId,dbemp.UserId);
           Assert.AreEqual("test", dbemp.Name);
           Assert.AreEqual("1234567890",dbemp.Number);
       }
    }
}
